/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.unicauca.opentextbook.entidades;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Gamificaion
 */
@Entity
@Table(name = "PERTENECE", catalog = "", schema = "OPENTEXTBOOK", uniqueConstraints = {
    @UniqueConstraint(columnNames = {"IDUSUARIO", "IDGRUPO", "IDROL"})})
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Pertenece.findAll", query = "SELECT p FROM Pertenece p")})
public class Pertenece implements Serializable {
    private static final long serialVersionUID = 1L;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqPertenece")
    @SequenceGenerator(name="seqPertenece", sequenceName="seqPertenece", initialValue=1, allocationSize=1)
    @Basic(optional = false)
    @NotNull
    @Column(name = "IDPERTENECE", nullable = false, precision = 0, scale = -127)
    private int idPertenece;
    @JoinColumn(name = "IDUSUARIO", referencedColumnName = "IDUSUARIO", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Usuario usuario;
    @JoinColumn(name = "IDROL", referencedColumnName = "IDROL", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Rol rol;
    @JoinColumn(name = "IDGRUPO", referencedColumnName = "IDGRUPO", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Grupo grupo;

    //Getters y Setters
    public int getIdPertenece() {
        return idPertenece;
    }

    public void setIdPertenece(int idPertenece) {
        this.idPertenece = idPertenece;
    }

    public Usuario getUsuario() {
        return usuario;
    }

    public void setUsuario(Usuario usuario) {
        this.usuario = usuario;
    }

    public Rol getRol() {
        return rol;
    }

    public void setRol(Rol rol) {
        this.rol = rol;
    }

    public Grupo getGrupo() {
        return grupo;
    }

    public void setGrupo(Grupo grupo) {
        this.grupo = grupo;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += idPertenece;
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Pertenece)) {
            return false;
        }
        Pertenece other = (Pertenece) object;
        if (this.idPertenece != other.idPertenece) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return String.valueOf(idPertenece);
    }
    
}
